<template>
  <div>
    <el-dialog
      :title="$t('gengXinKuCun')"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      :before-close="handleClose"
    >
      <el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
        <el-form-item :label="$t('shangPinMingCheng')">{{ formData.storeName }}</el-form-item>
        <el-form-item :label="$t('kuCunShu')" prop="stock">
          <el-input-number v-model="formData.stock" type="number" :precision="0" :min="0" :max="99999999" controls-position="right" :placeholder="$t('qingShuRuKuCunShu')" />
        </el-form-item>
        <el-form-item label="商品价格" prop="price">
          <el-input-number v-model.number="formData.price" type="number" :min="0.01" :max="99999999.99" :precision="2" controls-position="right" placeholder="请输入商品价格" />
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="onSubmit">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { updateStock } from '@/api/store'
export default {
  components: {

  },
  props: {
  },
  data() {
    return {
      dialogVisible: false,
      formData: {
        storeName: '',
        skuCode: '',
        stock: 0,
        price: 0
      },
      rules: {
        'stock': { required: true, message: this.$t('qingShuRuKuCunShu'), trigger: ['blur', 'change'] }, // 库存数
        'price': [{ required: true, message: '请输入商品价格', trigger: ['blur', 'change'] }] // 折扣价
      }
    }
  },
  methods: {
    show(row) {
      this.dialogVisible = true
      this.formData.storeName = row.storeName
      this.formData.skuCode = row.skuCode
      this.formData.stock = row.stock
      this.formData.price = row.price
    },
    handleClose() {
      this.dialogVisible = false
      this.$refs['formRef'].resetFields()
    },
    onSubmit() {
      this.$refs['formRef'].validate((valid) => {
        if (valid) {
          updateStock(this.formData).then(res => {
            this.$message.success(this.$t('caoZuoChengGong'))
            this.$emit('getList')
            this.handleClose()
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
